home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / carriage_ret.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-07  |  2.4 KB  |  78 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record
  3.  * Copyright (C) 1993 by Charles Sandmann (sandmann@clio.rice.edu)
  4.  * 
  5.  * This file is part of ED.
  6.  * 
  7.  * ED is free software; you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation.
  9.  * 
  10.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  13.  * 
  14.  * You should have received a copy of the GNU General Public License along with ED
  15.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  16.  * Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18. #include "opsys.h"
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include "memory.h"
  24. #include "rec.h"
  25. #include "window.h"
  26. #include "ed_dec.h"
  27. #include "buffer.h"
  28.  
  29. /******************************************************************************\
  30. |Routine: carriage_return
  31. |Callby: cfrendly edit insert word_fill
  32. |Purpose: To do what is required when the user hits carriage return while
  33. |         editing. This always creates a new record, and usually splits an
  34. |         existing record. This routine also implements insertion of tabs in
  35. |         the new record to make it line up with the previous record, if the
  36. |         TAB_AUTO flag is set.
  37. |Arguments:
  38. |    repeat is the repeat count applied to the action.
  39. \******************************************************************************/
  40. void carriage_return(repeat)
  41. Int repeat;
  42. {
  43.     buf_node cr;
  44.     register rec_ptr r;
  45.     register Int i,ntabs;
  46.  
  47. /* count leading tabs in previous record */
  48.     ntabs = 0;
  49.     if(CURREC != BASE && TAB_AUTO && !OVERSTRIKE) /* CWS 11-93 over bug */
  50.     {
  51.         for(ntabs = 0;CURREC->data[ntabs] == '\t' || CURREC->data[ntabs] == ' ';ntabs++);
  52.         if(CURBYT < ntabs)
  53.             ntabs = CURBYT;
  54.     }
  55. /* set up a buffer to hold the new record(s), and create and insert the new record(s) */
  56.     cr.nrecs = repeat + 1;
  57.     cr.direction = 1;
  58.     cr.first = (rec_ptr)&cr.first;
  59.     cr.last = (rec_ptr)&cr.first;
  60.     for(i = 0;i <= repeat;i++)
  61.     {
  62.         r = (rec_ptr)imalloc(sizeof(rec_node));
  63.         if((r->length = (!i)? 0 : ntabs))
  64.         {
  65.             r->data = (Char *)imalloc(ntabs + 1);
  66.             memcpy(r->data,CURREC->data,ntabs);
  67.             r->recflags = 1;    /* it is a freeable buffer */
  68.         }
  69.         else
  70.             r->data = NULL;
  71.         insq(r,cr.last);
  72.     }
  73. /* put it all in the file, and free storage */
  74.     insert(&cr);
  75.     buffer_empty(&cr);
  76. }
  77.  
  78.